package com.lagou.controller;


import com.lagou.pojo.Resume;
import com.lagou.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("/resume")
@Controller
public class ResumeController {

    @Autowired
    private ResumeService resumeService;

    /**
     * 查找所有数据
     * @return
     */
    @ResponseBody
    @RequestMapping("/findAll")
    public List<Resume> findAll() {
        return resumeService.findAll();
    }

    /**
     * 查找单条数据
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/findOne")
    public Resume findOne(Long id) {
        return resumeService.findById(id);
    }

    /**
     * 删除单条数据
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteById")
    public String deleteById(Long id) {
        resumeService.deleteById(id);
        return STATUS_OK;
    }

    /**
     * 增加 或者 修改 单条数据
     * @param resume
     * @return
     */
    @ResponseBody
    @RequestMapping("/update")
    public String update(Resume resume) {
        Resume save = resumeService.save(resume);
        return save == null ? STATUS_NOT_OK : STATUS_OK;
    }

    private static String STATUS_OK = "OK";
    private static String STATUS_NOT_OK = "NotOk";

}

























































